package com.hogan.hoganproject.base.app;

import android.app.Application;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import androidx.multidex.MultiDex;

/**
 * Author: chenhu
 * Time: 2020/8/28 14:43
 * Description do somethings
 */
public class HoganApplication extends Application {

    private static HoganApplication instance;
    private int screenWidth, screenHeight;

    public int getScreenWidth() {
        return screenWidth;
    }

    public int getScreenHeight() {
        return screenHeight;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        initScreenWidthAndHeight();
    }

    public static HoganApplication getInstance() {
        return instance;
    }
    /**
     * 得到手机的宽度与高度
     */
    private void initScreenWidthAndHeight() {
        DisplayMetrics metric = new DisplayMetrics();
        WindowManager wm = (WindowManager) getApplicationContext()
                .getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(metric);
        screenWidth = metric.widthPixels; // 屏幕宽度（像素）
        screenHeight = metric.heightPixels; // 屏幕高度（像素）
    }
}
